home *** CD-ROM | disk | FTP | other *** search
- ;EDITOR.ASM -- Field input routine for use with
- ; Microsoft QB 4.x, PDS 7.x & VB/DOS 1.x.
-
- .Model Medium, Basic
- Extrn StringAddress:Proc ;PDS, VB/DOS string
- Extrn StringLength:Proc ;functions.
-
- .Data
- CsrSize DB ? ;Bottom scan line of cursor.
- InsFlag DB ? ;Insert/overtype mode.
- MonSeg DW ? ;Video segment.
-
- .Code
- Proc Editor Uses DS ES DI SI, In$:Word, Start:Word, Row:Word, Col:Word, Colr:Word
-
- ;Local vars:
- ; Len = LEN(In$)
- ; StrPtr = Offset of current char
- ; StrSeg = Segment In$
- ; StrOfs = Offset of In$
- ; Wide = Screen width in bytes
-
- Local Len:Word, StrPtr:Word, StrSeg:Word, StrOfs:Word, Wide:Word
-
- Cmp MonSeg, 0 ;MonSeg = 0?
- Jnz Mono ;No, skip init code.
- Mov CsrSize, 12 ;Assume mono.
- Mov MonSeg, 0B000h
- Xor AX, AX
- Mov ES, AX ;Point ES to low memory.
- Mov AL, ES:[463h] ;Check monitor type.
- Cmp AL, 0B4h
- Je Mono
- Mov CsrSize, 7 ;Color monitor.
- Add MonSeg, 800h
-
- Mono:
- Mov AH, 0Fh ;Get video mode.
- Push BP ;Some old BIOS's destroy
- Int 10h ;BP during Int 10h.
- Pop BP ;Returns # columns in AH.
- Mov AL, AH ;Put columns in AL.
- Cbw ;Convert byte to word.
- Shl AX, 1 ;Double to get # bytes.
- Mov Wide, AX ;Save it in Wide.
-
- Mov SI, Start
- Mov AX, [SI]
- Mov StrPtr, AX ;Save string pointer.
- Cmp StrPtr, 0 ;If StrPtr then StrPtr = StrPtr - 1
- Jz InitString
- Dec StrPtr
-
- InitString:
- Mov SI, In$ ;Put descriptor address in SI.
- Push SI
- Call StringLength
- Cmp AX, 0 ;Is In$ null?
- Jz Shortcut ;If so, exit.
- Mov Len, AX ;Len = LEN(In$)
- Push SI ;StringAddress returns
- Call StringAddress ;location of string data.
- Mov StrSeg, DX ;Save segment
- Mov StrOfs, AX ;and offset.
-
- ;============================================
- ; To use with QB, replace the lines between
- ; the InitString label and these comments
- ; with the following:
- ;============================================
-
- ;Mov SI, In$ ;Put descriptor address in SI.
- ;Mov CX, [SI] ;Put LEN(In$) in CX.
- ;Jcxz Shortcut ;Exit if length is zero.
- ;Mov Len, CX
- ;Mov DX, DS ;Set StrSeg to default
- ;Mov StrSeg, DX ;data segment.
- ;Mov CX, [SI+2]
- ;Mov StrOfs, CX ;Save string offset.
-
- Call PrintString
- Call SetCursor
-
- GetKey:
- Mov AH, 2 ;LOCATE Row, Col + StrPtr
- Xor BH, BH ;Point to video page 0.
- Mov SI, Col
- Mov DX, [SI] ;Col in DX.
- Dec DX ;Convert 1-80 to 0-79.
- Add DX, StrPtr ;Add StrPtr.
- Mov SI, Row
- Mov DH, [SI] ;Row in DH.
- Dec DH ;Convert 1-25 to 0-24.
- Push BP
- Int 10h
- Pop BP
-
- Call WaitKey ;Get a key.
- Cmp AL, 0 ;If AL = 0, then an
- Jz Extended ;extended key was pressed.
- Xor AH, AH ;Clear AH so that AX will
- ;contain std key code.
- Cmp AL, 13 ;Exit if Enter or
- Je Shortcut ;Escape are pressed.
- Cmp AL, 27
- Je Shortcut
- Cmp AL, 8 ;Handle Backspace here.
- Jne Alpha ;Process other keys at Alpha.
- Cmp StrPtr, 0 ;Can't Backspace if already
- Jz GetKey ;at first character!
- Dec StrPtr ;StrPtr = StrPtr - 1
- Jmp Shift ;Shift text to the left.
- ;(see Delete code below)
- Repeat:
- Call PrintString
- Jmp GetKey
- Extended:
- Jmp ExtKey
- Shortcut:
- Jmp Exit
-
- Alpha:
- Cmp AL, 32
- Jb Shortcut
- Mov CX, Len
- Cmp StrPtr, CX ;If StrPtr < (Len + 1)...
- Jnb Repeat
- Inc StrPtr ;StrPtr = StrPtr + 1
-
- Mov BX, StrSeg
- Mov ES, BX ;Set ES to In$ segment.
- Cmp InsFlag, 0 ;If not insert mode,
- Jz PrintChar ;skip the next part.
-
- Push ES ;Set DS to ES.
- Pop DS
- Mov SI, StrOfs ;Point DS:SI at penultimate
- Add SI, CX ;character of In$.
- Dec SI
- Dec SI
- Mov DI, SI ;Set DI to SI + 1.
- Inc DI
- Mov BX, StrPtr
- Sub CX, BX ;Copy Len - StrPtr chars.
- Std ;Copy from right to left.
- Rep Movsb ;Do it!
- Push SS ;Reset DS.
- Pop DS
- Cld ;Clear direction flag.
-
- PrintChar:
- Mov DI, StrOfs
- Add DI, StrPtr
- Dec DI
- Mov ES:[DI], AL
- Jmp Repeat
-
- ExtKey:
- Mov AL, AH ;Convert extended key
- Cbw ;into negative code in AX.
- Neg AX
-
- Home:
- Cmp AX, -71
- Jne EndKey
- Mov StrPtr, 0
- Jmp Repeat
-
- EndKey:
- Cmp AX, -79
- Jne Left
- Push AX ;Save AX (key code).
- Mov BX, StrSeg
- Mov ES, BX ;Point ES:DI at last char.
- Mov DI, StrOfs
- Mov CX, Len ;Length in CX.
- Add DI, CX
- Dec DI
- Std ;Search backward
- Mov AL, 32 ;for a non-space.
- Repe Scasb
- Jcxz NotFound
- Inc CX
- NotFound:
- Mov StrPtr, CX
- Cld
- Pop AX
- Jmp Repeat
-
- Left:
- Cmp AX, -75
- Jne Right
- Cmp StrPtr, 0
- Jz GoBack
- Dec StrPtr
- Jmp Repeat
-
- Right:
- Cmp AX, -77
- Jne Insert
- Mov BX, Len
- Cmp StrPtr, BX
- Jnb GoBack
- Inc StrPtr
- Jmp Repeat
-
- Insert:
- Cmp AX, -82
- Jne Delete
- Mov BL, InsFlag
- Xor BL, -1
- Mov InsFlag, BL
- Call SetCursor
- Jmp Repeat
-
- Delete:
- Cmp AX, -83
- Jne GoBack
- Shift:
- Mov BX, StrSeg
- Mov DS, BX ;Point DS:SI at StrPtr + 1.
- Mov SI, StrOfs
- Mov BX, StrPtr
- Inc BX
- Add SI, BX
- Push DS ;Set ES to DS.
- Pop ES
- Mov DI, SI ;Set DI to SI - 1.
- Dec DI
- Mov CX, Len ;Copy Len - StrPtr chars.
- Sub CX, BX
- Cld ;Copy forward.
- Rep Movsb ;Do it!
- Mov Byte Ptr ES:[DI], 32
- Push SS ;Reset DS.
- Pop DS
- GoBack:
- Jmp Repeat
-
- Exit:
- Mov BX, StrPtr ;Put StrPtr + 1
- Inc BX ;in Start parameter
- Mov SI, Start ;(AX contains code of
- Mov [SI], BX ;last keystroke).
- Ret
-
- Editor Endp
- PrintString Proc Near
-
- Push DS
- Mov SI, Row
- Mov AX, [SI] ;Put current row number into AX.
- Dec AX ;Convert 1-25 to 0-24.
- Mov BX, Wide ;Multiply by width to get row address.
- Mul BX ;Result ends up in AX.
-
- Mov SI, Col
- Mov BX, [SI] ;Same deal for column.
- Dec BX
- Shl BX, 1 ;Double it for chars and attributes.
- Add AX, BX ;Add to base address.
-
- Mov BX, MonSeg
- Mov ES, BX ;Point ES to video segment
- Mov DI, AX ;and DI to screen address.
- Mov SI, Colr
- Mov AH, [SI] ;Set AH to color attribute.
- Mov BX, StrSeg
- Mov DS, BX
- Mov SI, StrOfs ;Point DS:SI to In$
- Mov CX, Len ;and string length in CX.
- Cld ;Copy forward.
-
- PutChar:
- Lodsb
- Stosw
- Loop PutChar
- Pop DS
- Ret
-
- PrintString Endp
- SetCursor Proc Near
-
- Xor CH, CH ;Set top of cursor to 0.
- Cmp InsFlag, 0 ;InsFlag = 0?
- Jnz InsMode ;If not, skip ahead.
- Mov CH, CsrSize ;Top cursor scan line
- Dec CH ;(CsrSize - 1) in CH.
-
- InsMode:
- Mov CL, CsrSize ;Set bottom to CsrSize.
- Push AX ;Save AX (key code)
- Push BP
- Mov AH, 1 ;Set cursor size.
- Int 10h
- Pop BP
- Pop AX
- Ret
-
- SetCursor Endp
- WaitKey Proc Near
-
- Xor AX, AX
- Mov ES, AX ;Clear keyboard buffer:
- Mov AX, ES:[41Ah] ; Get kybd buffer head ptr
- Mov ES:[41Ch], AX ; Set tail equal to head
- Mov AH,0 ;Wait for a keystroke.
- Int 16h ;Key code returned in AX.
- Ret
-
- WaitKey Endp
- End
-
-